<?php if (!defined('THINK_PATH')) exit();?>
<style>
	#js_appmsg_editor .error{
		border: 1px solid #F06060;
	}
	#js_appmsg_editor .success{
		border: 1px solid #66C88D;
	}
</style>

<script type="text/javascript">
	$(function(){
		CKEDITOR.replace('TextArea1');
		CKEDITOR.instances['TextArea1'].on("instanceReady", function () {
      		$('iframe').first().contents().find('body').blur(ckeditorKeyUp);
   		}); 
   		
		$('.editBtn').click(editBtnClick);
		$(".input_field").change(asynFiled);
		$(".input_field").keyup(asynFiled);
		
		var type="<?php echo ($article["type"]); ?>";
		if(type!=""){
			$('#type_<?php echo ($article["type"]); ?>').show();
		}
	});
	function ckeditorKeyUp(){
		var data=CKEDITOR.instances['TextArea1'].getData();
		$(".currentEditItem").parent().find("input[name='mainText']").val(data);
	}
	
	function ajaxFileUpload2(url,downLoadUrl){
	$.ajaxFileUpload({
        url:url,
        secureuri:false,
        fileElementId:"uploadify",
		dataType:"json",
		success:function(attach,status){
			$(".currentEditItem").parent().find("input[name='imgId[]']").val(attach.id);
			$(".currentEditItem").parent().parent().find(".imgClass").attr("src",getRootPath()+downLoadUrl+"/id/"+attach.id);
			$(".currentEditItem").parent().parent().find(".default").removeClass("default");
			$(".currentEditItem").parent().parent().find(".imgClass").show();
		 	$("#smallImgId").attr("src",getRootPath()+downLoadUrl+"/id/"+attach.id);
		 	$("#fmPid").show();
		},
		error:function(data,status,e){
		alert(e);
		}
	});
	return false;	
}
	
	function editBtnClick(){
        var downLoadUrl="<?php echo U('File/downLoad');?>";
		var $this=$(this);
		var index=$('.editBtn').index(this);
		if(index==0){
			$('#js_appmsg_editor').css('padding-top',"0px");
		}else{
			var top=(index-1)*102+184;
			$('#js_appmsg_editor').css('padding-top',top+"px");
		}
		$('.currentEditItem').removeClass('currentEditItem');
		$this.addClass('currentEditItem');
		var inputs=$this.parent().find('input');
		var imgId=$this.parent().find("input[name='imgId[]']").val();
		var mainText=$(".currentEditItem").parent().find("input[name='mainText[]']").val();
		$('iframe').first().contents().find('body').html(mainText);
		if(imgId!="" && imgId!=0){
			$("#smallImgId").attr("src",getRootPath()+downLoadUrl+"/id/"+imgId);
			$("#fmPid").show();
		}else{
			$("#smallImgId").attr("src","");
			$("#fmPid").hide();
		}
		for(var i=0;i<inputs.size();i++){
			var $input=$(inputs.get(i));
			var selector='*[data-field="'+ $input.attr('name')+'"]';
			var $field=$(selector);
			$field.first().val($input.val());
		}
		var type=$this.parent().find('input[name="type[]"]').first().val();
		$("#article_type"+type).click();
	}
</script>
<style>
.first{
	padding-top: 184px;
}
.headfirst{
	padding-top: 0px;
}

</style>
<div class="container-fluid" style="height: 100%;padding-top: 10px">
<!-- 左侧 -->
<div id="pane0_2" class='row pane' style="padding: 30px 20px 0;">  
	<form id="moreTuWenFrom">
		<input type="hidden" name="graphicId"  value="<?php echo ($graphic["id"]); ?>">
		<div class="media_preview_area">
			<div class="appmsg multi editing">
				<div id="js_appmsg_preview" class="appmsg_content">
					<div id="appmsgItem1" class="js_appmsg_item " data-id="1" data-fileid="">
						<div class="appmsg_info">
							<em class="appmsg_date"></em>
						</div>
						<div class="cover_appmsg_item">
							<h4 class="appmsg_title">
								<a target="_blank" onclick="return false;" href="javascript:void(0);" class="titleClass">
                                    <?php if($article.head_title): echo ($article["head_title"]); ?>
                                        <?php else: ?>
                                        标题<?php endif; ?>
								</a>
							</h4>
							<div class="appmsg_thumb_wrp">
                                <?php if($article.img_id): ?><img class="js_appmsg_thumb appmsg_thumb imgClass" style="display: block;" src="<?php echo U('File/downLoad');?>/id/<?php echo ($article["img_id"]); ?>">
									<i class="appmsg_thumb ">封面图片</i>
								<?php else: ?>
									<img class="js_appmsg_thumb appmsg_thumb imgClass" src="">
									<i class="appmsg_thumb default">封面图片</i><?php endif; ?>
							</div>
							<div class="appmsg_edit_mask">
								<input type="hidden" name="author[]" value="<?php echo ($article["author"]); ?>">
								<input type="hidden" name="imgId[]" value="<?php echo ($article["img_id"]); ?>">
								<input type="hidden" name="mainText[]" value="<?php echo ($article["mainText"]); ?>">
								<input type="hidden" name="originalLink[]" value="<?php echo ($article["originalLink"]); ?>">
								<input type="hidden" name="headTitle[]" value="<?php echo ($article["head_title"]); ?>">
								<input type="hidden" name="type[]" value="<?php echo ($article["type"]); ?>">
								<input type="hidden" name="linkUrl[]" value="<?php echo ($article["linkUrl"]); ?>">
								<a class="icon18_common edit_gray js_edit editBtn currentEditItem" href="javascript:;" data-id="1" >编辑</a>
							</div>
						</div>
					</div>
                    <?php if($articleList): if(is_array($articleList)): $i = 0; $__LIST__ = $articleList;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$gra): $mod = ($i % 2 );++$i;?><div id="appmsgItem2" class="appmsg_item js_appmsg_item " data-id="2" data-fileid="">
                                <img class="js_appmsg_thumb appmsg_thumb imgClass" style="display: block;" src="<?php echo U('File/downLoad');?>/id/<?php echo ($gra["img_id"]); ?>">
                                <i class="appmsg_thumb ">缩略图2</i>
                                <h4 class="appmsg_title" >
                                    <a target="_blank" href="javascript:void(0);" onclick="return false;" class="titleClass"><?php echo ($gra["head_title"]); ?></a>
                                </h4>
                                <div class="appmsg_edit_mask">
                                    <input type="hidden" name="author[]" value="<?php echo ($gra["author"]); ?>">
                                    <input type="hidden" name="imgId[]" value="<?php echo ($gra["img_id"]); ?>">
                                    <input type="hidden" name="mainText[]" value="<?php echo ($gra["mainText"]); ?>">
                                    <input type="hidden" name="originalLink[]" value="<?php echo ($gra["originalLink"]); ?>">
                                    <input type="hidden" name="headTitle[]" value="<?php echo ($gra["head_title"]); ?>">
                                    <input type="hidden" name="type[]" value="<?php echo ($gra["type"]); ?>">
                                    <input type="hidden" name="linkUrl[]" value="<?php echo ($gra["linkUrl"]); ?>">
                                    <a class="icon18_common edit_gray js_edit editBtn" href="javascript:void(0);"  data-id="3">编辑</a>
                                    <a class="icon18_common del_gray js_del" href="javascript:void(0);" onclick="deleThisItem(this)" data-id="3">删除</a>
                                </div>
                            </div><?php endforeach; endif; else: echo "" ;endif; ?>
					<?php else: ?>
                        <div id="appmsgItem2" class="appmsg_item js_appmsg_item " data-id="2" data-fileid="">
                            <img class="js_appmsg_thumb appmsg_thumb imgClass" src="">
                            <i class="appmsg_thumb default">缩略图1</i>
                            <h4 class="appmsg_title" >
                                <a target="_blank" href="javascript:void(0);" onclick="return false;" class="titleClass">标题</a>
                            </h4>
                            <div class="appmsg_edit_mask">
                                <input type="hidden" name="author[]" >
                                <input type="hidden" name="imgId[]">
                                <input type="hidden" name="mainText[]">
                                <input type="hidden" name="originalLink[]">
                                <input type="hidden" name="headTitle[]">
                                <input type="hidden" name="type[]">
                                <input type="hidden" name="linkUrl[]">
                                <a class="icon18_common edit_gray js_edit editBtn" href="javascript:void(0);"  data-id="3">编辑</a>
                                <a class="icon18_common del_gray js_del" href="javascript:void(0);" onclick="deleThisItem(this)" data-id="3">删除</a>
                            </div>
                        </div><?php endif; ?>
					
				</div>
				<div class="appmsg_add">
					<a id="js_add_appmsg" href="javascript:void(0);" onclick="addSuoLueTu()">
					<i class="icon24_common add_gray">增加一条</i>
					</a>
				</div>
			</div>
		</div>
	</form>
	
	<!-- 右侧 -->
		<form>
		<div id="js_appmsg_editor" class="media_edit_area none" >
			<div class="appmsg_editor" style="margin-top: 0px;">
				<div class="inner">
					<div class="appmsg_edit_item">
						<label class="frm_label" for="">标题</label>
						<div class="frm_input_box">
						<input class="frm_input js_title input_field" data-field="headTitle[]" data-required type="text" style="border: none;" onkeyup="showmoreTitle(this)">
						</div>
					</div>
					<div class="appmsg_edit_item">
						<label class="frm_label" for="">
						<strong class="title">作者</strong>
						<p class="tips l">（选填）</p>
						</label>
						<div class="frm_input_box">
						<input class="frm_input js_author input_field" data-field="author[]" data-required type="text" style="border: none;">
						</div>
					</div>
					<div class="appmsg_edit_item">
						<label class="frm_label" for="">
							<strong class="title">封面</strong>
							<p class="js_cover_tip tips r">大图片建议尺寸：360像素 * 200像素</p>
						</label>
						<div class="frm_input_box">
							<div class="upload_box">
								<div class="upload_area" >
									<a id="js_appmsg_upload_cover" class="upload_access"  href="javascript:void(0);" width="50" height="22">
										<i class="icon18_common upload_gray"></i>
										上传
									</a>
									<ul class="upload_file_box" style="display: none;"></ul>
								</div>
							</div>
							<input type="file" id='uploadify' 
									class='btn blue-bg'
									style="width: 90px; opacity: 0; position: absolute; top: 0px;height: 30px;z-index: 999"
									name="attach" onchange="ajaxFileUpload2('<?php echo U('File/upload');?>','<?php echo U('File/downLoad');?>')">
							<p class="js_cover upload_preview" style="display: none;" id="fmPid">
								<img id="smallImgId" style="width: 100px;height: 70px;">
								<a class="js_removeCover none" onclick="deletefmP()" href="javascript:void(0);">删除</a>
							</p>
						</div>
						<div class="js_url_area dn appmsg_edit_item">
							<div class="frm_label" for="">消息类型</div>
                            <?php if(($article["type"] == 'article')): ?><input type="radio" name="none"    data-field="type[]"  value="article" checked onchange="showEditor(this.value)">文章消息
                                <input type="radio" name="none"    data-field="type[]"  value="link" onchange="showEditor(this.value)">网络链接
                                <?php else: ?>
                                <input type="radio" name="none"   data-field="type[]"  id="article_typearticle"  value="article" onchange="showEditor(this.value)">文章消息
                                <input type="radio" name="none"   data-field="type[]"  id="article_typelink"   value="link" checked onchange="showEditor(this.value)">网络链接<?php endif; ?>
                        </div>
						<div id='type_article' class='article_type'>
							<div class="appmsg_edit_item">
								<label class="frm_label" for="">
									<strong class="title">正文</strong>
								</label>
								<textarea id="TextArea1" cols="20" rows="2" class="ckeditor input_field"  data-field="mainText[]" name="article.mainText"><?php echo ($article["mainText"]); ?></textarea>
							</div>
							<p>
								<a class="js_addURL" onclick="showYuanWenlj(this)" href="javascript:void(0);">添加原文链接</a>
							</p>
							<div class="js_url_area dn appmsg_edit_item" style="display: none;" id="yuanwenljId">
								<label class="frm_label" for="">原文链接</label>
								<div class="frm_input_box">
								<input class="js_url frm_input input_field" name="originalLink[]"  data-field="originalLink[]"  value="" type="text" style="border: none;">
								</div>
							</div>
						</div>
						<div id='type_link' class='article_type'>
							<div class="js_url_area dn appmsg_edit_item"   id="yuanwenljId">
								<label class="frm_label" for="">链接地址</label>
								<div class="frm_input_box">
								<input class="js_url frm_input input_field" name="linkUrl[]" value=""  data-field="linkUrl[]"  id="yuanwenljTextId" type="text" style="border: none;">
								</div>
							</div>
						</div>
						<i class="arrow arrow_out" style="margin-top: 0px;"></i>
						<i class="arrow arrow_in" style="margin-top: 0px;"></i>
						<div class="mask" style="display: none;"></div>
					</div>
				</div>
			</div>
		</div>
	</form>	
	<div class="tool_area">
			<div class="tool_bar">
				<span id="js_preview" class="btns btn_input btn_primary">
					<input type="button" value="预览" class="buttons">
				</span>
				<span id="js_submit" class="btns btn_input btn_primary">
					<input type="button" value="保存" class="buttons" onclick="saveMoreTuWen('<?php echo U('Message/saveDuotuwen');?>')">
				</span>
				</div>
		</div>
	</div>
</div>

<div style="display: none;" id="suoluetuId">
	
	<div id="appmsgItem2" class="appmsg_item js_appmsg_item " data-id="" data-fileid="" >
		<img class="js_appmsg_thumb appmsg_thumb imgClass" src="">
		<i class="appmsg_thumb default">缩略图</i>
		<h4 class="appmsg_title" >
			<a target="_blank" href="javascript:void(0);" onclick="return false;" class="titleClass">标题</a>
		</h4>
		<div class="appmsg_edit_mask">
			<input type="hidden" name="author[]">
			<input type="hidden" name="imgId[]">
			<input type="hidden" name="mainText[]">
			<input type="hidden" name="originalLink[]">
			<input type="hidden" name="headTitle[]">
			<input type="hidden" name="type[]" value="article">
			<input type="hidden" name="linkUrl[]">
			<a class="icon18_common edit_gray js_edit editBtn" href="javascript:void(0);"   data-id="3">编辑</a>
			<a class="icon18_common del_gray js_del" href="javascript:void(0);" onclick="deleThisItem(this)" data-id="3">删除</a>
		</div>
	</div>
</div>